package tech.aistar.corejava.day13;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/8/2
 * @Version: 1.0
 */
public class PrintWriterDemo {

    public static void main(String[] args) {
        PrintWriter out = null;

        try {
            //不自动刷新
            //out = new PrintWriter(new FileWriter("writer.txt"));

            //自动刷新缓冲区
            out = new PrintWriter(new FileWriter("writer.txt"),true);

            //1.自动刷新 - 2.追加写入
            //第一个true - 是否追加写入FileWrite(String pathname,boolean append);
            //第二个true - 是否自动刷新缓存 PrintWriter(Writer w,boolean autoFlush);
            out = new PrintWriter(new FileWriter("writer.txt",true),true);


            out.println("hello");
            out.println("hello");

            //手动刷新
            //out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if (null != out){
                //关闭流之前,会强制刷新缓冲区
                out.close();
            }
        }

    }
}
